<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 7、完成一个十进制转换成其它进制的函数(convert(512,2) :表示把十进制的512转成2进制)) -->
     <script>
            function covert(num,s){
                return parseInt(num).toString(s)
            }
            console.log(covert(512,2));
        </script>  
    <!-- <script>
        function covert(num,s) {
            var reult = [];
            if (num < 0) {
                return 0;
            }
            do {
                var temp = num % s;
                temp == 0 ? result.push('0') : result.push('1');
                num = Math.floor(num / s);
            }
            while (num != 0) {
                // 翻转数组
                result.reverse();
                return result.join('');
                // join()将数组转换为字符串，参数为分隔符，原数组不会改变
            }
        }

        covert(512,2);

    </script> -->
</body>

</html>